package com.robert.taibots;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageButton;

import androidx.appcompat.app.AppCompatActivity;

public class WebActivity extends AppCompatActivity implements View.OnClickListener {

    private WebView webView;
    private ImageButton backButton;
    @SuppressLint("SetJavaScriptEnabled")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.web_activity);

        backButton = (ImageButton) findViewById(R.id.backButton);
        backButton.setOnClickListener(this);
        Intent it2 = getIntent();
        String str = it2.getStringExtra("url_String");
        webView = new WebView(this);
        webView.getSettings().setJavaScriptEnabled(true);  //设置WebView属性,运行执行js脚本
        if (str == null) {
            webView.loadUrl("https://doc-hosting.flycricket.io/rbt-robert-privacy-policy/27e9406f-d822-49ef-88d5-289378c13bde/privacy");
        } else {
            webView.loadUrl(str);
        }
        webView.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                view.loadUrl(request.getUrl().toString());
                return true;
            }
            @Override
            public void  onPageStarted(WebView view, String url, Bitmap favicon) {
                //设定加载开始的操作

            }

            @Override
            public void onPageFinished(WebView view, String url) {
                //设定加载结束的操作
            }
            public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {

            }
        });
        setContentView(webView);

    }

    @Override
    public void onClick(View view) {
        finish();
    }
}
